package com.mcptt.db.model;

import java.io.Serializable;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.DatabaseUtils;

import com.cloudptt.api.comm.CheckData;
import com.mcptt.db.DbConst;

public class GroupMembInfo implements Serializable,Comparable<GroupMembInfo>
{   
    public static final int QueryMembStatus_Begin = 1;
    public static final int QueryMembStatus_End = 2;

    public static final String UserType_User = "0";
    public static final String UserType_Group = "1";

    public static final String Init_Status = "0";

    public static final String Online_StatusDscp = "Online";
    public static final Integer Online_Order = 0;

    public static final String Offline_StatusDscp = "";
    public static final Integer Offline_Order = 1;

    private String groupNum;
    //	private String userId;
    private String name;
    private String num;
    private int priority = 0;
    private String status;	
    private String statusDscp;	
    private Integer order = Offline_Order;


    public GroupMembInfo(Cursor c)
    {
	ContentValues args = new ContentValues();
	DatabaseUtils.cursorRowToContentValues(c, args);
	createFromContentValue(args);
    }



    public GroupMembInfo(String groupNum,String num,String name,String priority) {
	// TODO Auto-generated constructor stub
	this.groupNum = groupNum;
	this.num = num;
	this.name = name;
	this.priority = CheckData.parseInt(priority);
	this.status = Init_Status;
	this.statusDscp = Offline_StatusDscp;
	this.order = Offline_Order;
    }


    /**
     * Pack the object content value to store
     * 
     * @return The content value representing the message
     */
    public ContentValues getContentValues() {
	ContentValues cv = new ContentValues();
	cv.put(DbConst.COL_MEMBER_GROUP_NUM, groupNum);
	//		cv.put(DbConst.COL_MEMBER_PUID,userId);
	cv.put(DbConst.COL_MEMBER_NAME, name);
	cv.put(DbConst.COL_MEMBER_NUM, num);
	cv.put(DbConst.COL_MEMBER_STATUS, priority);
	cv.put(DbConst.COL_MEMBER_STATUS, status);

	return cv;
    }

    public final void createFromContentValue(ContentValues args) {

	String tmp_s;

	tmp_s = args.getAsString(DbConst.COL_MEMBER_GROUP_NUM);
	if(tmp_s != null) {
	    groupNum = tmp_s;
	}
	//		tmp_s = args.getAsString(DbConst.COL_MEMBER_PUID);
	//		if(tmp_s != null) {
	//			userId = tmp_s;
	//		}
	tmp_s = args.getAsString(DbConst.COL_MEMBER_NAME);
	if(tmp_s != null) {
	    name = tmp_s;
	}
	tmp_s = args.getAsString(DbConst.COL_MEMBER_NUM);
	if(tmp_s != null) {
	    num = tmp_s;
	}
	tmp_s = args.getAsString(DbConst.COL_MEMBER_PRIORITY);
	if(tmp_s != null) {
	    priority = CheckData.parseInt(tmp_s);
	}
	tmp_s = args.getAsString(DbConst.COL_MEMBER_STATUS);
	if(tmp_s != null) {
	    status = tmp_s;
	}
    }


    public String getGroupNum() {
	return groupNum;
    }
//    public void setGroupId(String groupId) {
//	this.groupNum = groupId;
//    }
    //	public String getUserId() {
    //		return userId;
    //	}
    //	public void setUserId(String userId) {
    //		this.userId = userId;
    //	}
    public String getName() {
	return name;
    }
//    public void setName(String name) {
//	this.name = name;
//    }
    public String getNum() {
	return num;
    }
//    public void setNum(String num) {
//	this.num = num;
//    }
    public int getPriority()
    {
	return priority;
    }
//    public static String getUsertypeUser() {
//	return UserType_User;
//    }
//    public static String getUsertypeGroup() {
//	return UserType_Group;
//    }

    public void setStatus(String status) {
	this.status = status;
	if(status.equals("1"))
	{
	    this.statusDscp = Online_StatusDscp;
	    this.order = Online_Order;
	}
	else
	{
	    this.statusDscp = Offline_StatusDscp;
	    this.order = Offline_Order;
	}
    }

//    public boolean isValidStatus()
//    {
//	if(status.equals("2")
//		||status.equals("4")||status.equals("5"))
//	{
//	    return false;
//	}
//	return true;
//    }
//
//    public boolean isOnline()
//    {
//	if(status.equals("1"))
//	{
//	    return true;
//	}
//	return false;
//    }
//
    public String getStatus() {
	return status;
    }

    public String getStatusDscp() {
	return this.statusDscp;
    }


    public String getDescpStr()
    {
	//		String str = name + "(" + mdn + ")";
	//		return str;
	return name;
    }

    public Integer getOrder() {
	return order;
    }

    @Override
    public int compareTo(GroupMembInfo arg0) {
	return this.getOrder().compareTo(arg0.getOrder());
    }

    public String toString()
    {
	StringBuffer buffer = new StringBuffer("GroupMembInfo:");
	buffer.append("order = ").append(order).append(",");
	buffer.append("groupNum = ").append(groupNum).append(",");
	//		buffer.append("userId = ").append(userId).append(",");
	buffer.append("name = ").append(name).append(",");
	buffer.append("mdn = ").append(num).append(",");
	buffer.append("status = ").append(status).append(",");
	buffer.append("statusDscp = ").append(statusDscp).append(";");

	return buffer.toString();
    }
}
